<template>
  <ContentWrap title="主数据">
    <el-form
      :model="ff"
      :rules="rules"
      label-position="top"
      :inline="false"
      class="demo-form-inline"
    >
      <el-form-item
        :prop="data.field"
        :label="data.label"
        v-for="data in props.detailSchema"
        :key="data.field"
      >
        <el-input
          v-if="data.field !== 'code' && data.field !== 'name' && data.field !== 'creation_time'"
          style="width: 200px"
          v-model="ff[data.field]"
          :placeholder="`请输入相应的${data.label}`"
        />
        <el-select v-if="data.field == 'code'" v-model="ff.code" placeholder="请选择">
          <el-option
            v-for="(data1, index1) in options[1]"
            :key="index1"
            :label="data1.label"
            :value="data1.value"
          />
        </el-select>
        <el-select v-if="data.field == 'name'" v-model="ff.name" placeholder="请选择">
          <el-option
            v-for="(data1, index1) in options[0]"
            :key="index1"
            :label="data1.label"
            :value="data1.value"
          />
        </el-select>
        <el-date-picker
          v-if="data.field == 'creation_time'"
          v-model="ff.creation_time"
          type="date"
          placeholder="请输入相应的创建时间"
          :clearable="true"
          style="width: 500px"
        />
      </el-form-item>
    </el-form>
  </ContentWrap>
</template>

<script setup lang="ts">
import { PropType, reactive } from 'vue'
import { required } from '@/utils/formRules'
import type { FormRules } from 'element-plus'
const props = defineProps({
  currentRow: {
    type: Object as PropType<Nullable<any>>,
    default: () => null
  },
  detailSchema: {
    type: Array as PropType<DescriptionsSchema[]>,
    default: () => []
  }
})
console.log(props.detailSchema)

// 必填
const rules = reactive<FormRules>({
  code: [required],
  name: [required],
  // address: [required],
  // creation_time: [required],
  phone: [required]
  // operator_name: [required]
})
// 结束后填写的信息
const ff = reactive({
  code: '',
  name: '',
  jurisdiction: '',
  creation_time: '',
  postal_code: '',
  phone: ''
})
defineExpose([ff])

const options = [
  [
    {
      value: '猪',
      label: '猪'
    },
    {
      value: '牛',
      label: '牛'
    },
    {
      value: '羊',
      label: '羊'
    }
  ],
  [
    {
      value: '出',
      label: '出'
    },
    {
      value: '入',
      label: '入'
    }
  ]
]
</script>

<style lang="scss" scoped>
.el-form {
  display: flex;
  flex-wrap: wrap;
}
.el-form > div {
  width: 50%;
}
</style>
